package cz.tpj.tests.database.mesto;

import static org.junit.Assert.*;

import java.util.ArrayList;
import java.util.Iterator;

import org.junit.Test;

import cz.tpj.database.mesto.City;
import cz.tpj.database.mesto.Table_city;
import cz.tpj.util.ErrorDatabase;
	

public class Table_cityTest {
	//testovaci nazev souboru
	private String name = "ščřžýřtice2211228564asda";
	private String cityID = null;
	
	@Test
	public void testGetInstance() {
		assertNotNull(Table_city.getInstance());
	}
	/*
	@Test
	public void testGetAllCity() {
		fail("Not yet implemented");
	}

	@Test
	public void testExistujeMesto() {
		fail("Not yet implemented");
	}
	 */
	@Test
	public void testInsertCity() {
		
		Table_city tc;
		City city = new City();
		ArrayList<City> allCities;
		Iterator<City> it = null;
		City c2;
        String s = null;
		//
        try {
        	//vlozi mesto
			city.setName(name);
			tc = Table_city.getInstance();
			cityID = tc.insertCity(city);
	        //nacte vsecky mesta 
	        allCities = tc.getAllCity();
	        it = allCities.iterator();
	        //najde jestli se v databazi mesto ulozilo
	        while(it.hasNext()){
	            c2 = it.next();
	            s = c2.getName();
	            if(s.equals(name)){
	                break;
	            }else{
	                s = null;
	            }
	        }
		} catch (ErrorDatabase e) {
			fail(e.getErrorCode());
		}
        assertNotNull(s);
	}
	/*
	@Test
	public void testGetCityNameFromId() {
		fail("Not yet implemented");
	}

	@Test
	public void testGetCondCity() {
		fail("Not yet implemented");
	}
	*/
	@Test
	public void testDeleteCity() {
		try {
			//boolean isDeleted = Table_city.getInstance().deleteCity(Integer.parseInt(cityID));
			//assertTrue(isDeleted);
			
		} catch (Exception e) {
			fail(e.toString());
		}
	}
	/*
	@Test
	public void testUpdateCity() {
		fail("Not yet implemented");
	}
	*/
}
